<template>
	<view class="container">
		<view class="images">
			<view class="imgs">
				<!-- <img :src="infoData.qrCode" style="width:100%;" alt=""> -->
				<QrCode style="margin: 0;" :id="'QrCode'" :width="180" :height="180" :codeUrl="infoData.cardNum" />
			</view>
			<view class="upbtn flex align-center">
				<img src="@/static/images/update.png" style="width:28rpx;" alt="">
				切换为院内二维码
			</view>
		</view>
		<uni-list>
			<!-- <uni-list-item showExtraIcon="true" :extraIcon="{type: 'person-filled'}" title="姓名"
				:rightText="$desensitizationName(infoData.name)" /> -->
				<uni-list-item showExtraIcon="true" :extraIcon="{type: 'person-filled'}" title="姓名"
					:rightText="infoData.name" />
			<uni-list-item showExtraIcon="true" :extraIcon="{type: 'phone-filled'}" title="身份证号"
				:rightText="$desensitizationNormalStr(infoData.idNum)" />
			<uni-list-item showExtraIcon="true" :extraIcon="{type: 'email-filled'}" title="手机号"
				:rightText="infoData.mobile" />
			<uni-list-item showExtraIcon="true" :extraIcon="{type: 'auth-filled'}" title="就诊卡号"
				:rightText="infoData.cardNum" />
			<!-- <uni-list-item showExtraIcon="true" :extraIcon="{type: 'person-filled'}" title="性别"
				:rightText="infoData.sex" :show-arrow="true" @click.native="changeSex"/> -->
		</uni-list>
		<u-button type="primary" style="width:90%;margin:10px 0 10px 5%;" @click.native="addHealth">设置为默认健康卡</u-button>
		<view class="secure" @click="secureCard">
			解绑电子健康卡>>
		</view>
	</view>
</template>

<script>
	import {
		getPatientBaseData,
		putPatientBase,
		deleteHealthCard,
		deletePatientBase
	} from "@/api/card/index.js"
	import {
		encrypt,
		decrypt
	} from '@/utils/sm4Util.js'
	import {
		EventBus
	} from "@/utils/event-bus.js"
	import QrCode from '@/components/qrcode/index.vue';
	export default {
		components: {
			QrCode
		},
		data() {
			return {
				infoData: {},
				ids:'',
			}
		},
		onLoad(options) {
			this.ids = decodeURIComponent(options.ids);
			console.log('最新接收到的this.ids===',this.ids)
			this.getData()
		},
		methods: {
			changeSex(){
			},
			getData() {
				// this.ids 已加密 等于下面代码
				let ids = {
					params: this.ids
				}
				// let ids = {
				// 	params: encrypt(JSON.stringify({
				// 		id: options.id,
				// 		sfzh: options.idNum
				// 	}))
				// }
				getPatientBaseData(ids).then(res => {
					this.infoData = res.data
				})
			},
			secureCard() {
				let _that = this
				this.$modal.confirm('确定解绑当前电子健康卡吗？').then(() => {
					let ids = {
						params: this.ids
					}
					deletePatientBase(ids).then(res => {
						_that.$msg("解绑成功!")
						EventBus.$emit('CardList', '')
						EventBus.$emit('loadVisitor', '')
						EventBus.$emit('loadFunction', '')
						if (JSON.parse(uni.getStorageSync('currentVisitCard')).cardNum == this.infoData
							.cardNum) {
							uni.removeStorageSync('currentVisitCard')
						}
						uni.navigateBack()
					})
				})
			},
			addHealth() {
				this.infoData.isDefault = 1
				putPatientBase(this.infoData).then(res => {
					this.$msg("设置成功!")
					EventBus.$emit('CardList', '')
					EventBus.$emit('loadVisitor', '')
					EventBus.$emit('loadFunction', '')
					uni.setStorageSync('currentVisitCard', JSON.stringify(this.infoData))
					uni.navigateBack()
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: rgb(245, 245, 245);
	}

	::v-deep .uni-list-item__content-title {
		font-size: 24rpx;
	}

	::v-deep .u-button--normal {
		font-size: 24rpx;
	}

	.images {
		width: 95%;
		margin: 0 auto;
		background: #fff;
		padding: 40rpx;
		text-align: center;
		margin-bottom: 10px;
		margin-top: 10px;

		.imgs {
			width: 350rpx;
			margin: 0 auto;
		}

		.upbtn {
			margin: 0 auto;
			background-color: rgb(78, 142, 255);
			border-radius: 4px;
			padding: 4px 1rem;
			display: flex;
			justify-content: center;
			margin-top: 10px;
			color: #fff;

			img {
				margin-right: 10px;
			}
		}
	}

	.uni-list {
		width: 95%;
		margin: 0 auto;
		border-radius: 8px;
	}

	.secure {
		width: 100%;
		text-align: center;
		color: #5190FD;
		font-size: 24rpx;
	}
</style>